<?php

namespace Biz\Resources\Passport;

use Lumen\Security\App\AppIdSecurity;
use Lumen\Http\Resources\Json\Resource;
use Lumen\Security\App\AppSecretSecurity;

/**
 * ClientResource.
 *
 * @license [http://www.85do.com] [杭州永奥网络科技有限公司]
 * @copyright Copyright (c) 2018-2026 Hangzhou Yongao Technology Co., Ltd. All rights reserved.
 */
class ClientResource extends Resource
{
    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     *
     * @return array
     */
    public function toArray($request)
    {
        $appIdSecurity     = new AppIdSecurity();
        $appSecretSecurity = new AppSecretSecurity($this->secret);

        return [
            'uid'            => $this->uid,
            'name'           => $this->name,
            'app_id'         => $appIdSecurity->encode($this->id),
            $this->mergeWhen($this->isShowSecret(), [
                'app_secret' => $appSecretSecurity->encode($this->id),
            ]),
            'app_redirect'   => $this->redirect,
            'created_at'     => $this->created_at->getTimestamp(),
        ];
    }
}
